<template>
  <div class="main">
    <div class="content">
      <div class="top">
        <div class="box" id="dingdan">
          <div class="left">订单号</div>
          <input type="text" :value=shopId readonly  class="text_input">
        </div>
        <div class="box" id="nengfou">
          <div class="left">能否再次出售</div>
          <input type="checkbox" v-model="can_resell"  class="text_input">
        </div>
        <div class="box" id="tiaoxing">
          <div class="left">条形码</div>
          <input type="text" :value=barCode readonly class="text_input">
        </div>
        <div class="box" id="return_number">
          <div class="left">退货数量</div>
          <input type="text" v-model="count" class="text_input">
        </div>
        <div class="box" id="return_reason">
          <div class="left">退货原因</div>
          <input type="text" v-model="reason" class="text_input">
        </div>
      </div>
      <div class="bottom">
        <div class="button" @click="confirm" id="confirm">提交申请</div>
      </div>
    </div>
  </div>
</template>

<script>
    import salesPersonService from '../../service/aftersales'
    export default {
        name: "SalesReturn",
      data () {
        return {
          shopId: null,
          barCode: null,
          can_resell: false,
          count: null,
          reason: null
        }
      },
      async mounted() {
        this.shopId = this.$route.params.shopId
        this.barCode = this.$route.params.barCode
      },
      methods: {
        async confirm() {
          if (this.shopId==null||this.barCode==null) {
            alert("刷新页面失去数据")
            this.$router.push({name:'BeforeSales'})
            return
          }
          if (this.count==null||this.reason==null) {
            alert("请填写完整")
            return
          }
          const loginedUser = this.$store.getters.getLoginUser
          if (loginedUser == null) {
            return
          }
          const data = {
            serviceId: loginedUser.storeId,
            shopId: this.shopId,
            canResell: this.can_resell,
            barCode: this.barCode,
            count: this.count,
            reason: this.reason
          }
          let result = await salesPersonService.returnGoods(data)
          if (result.data.code == 2000){
            const answer = result.data.data
            if (answer.warehouseAddr == null || nswer.warehouseAddr == ""){
              var s = "请寄到工厂：" + answer.warehouseAddr
            } else  {
              var s = "请寄到：" + answer.storeName + "门店\n"
                + "地址：" + answer.storeAddr + "\n"
                + "收件人：" + answer.storeLeader + "\n"
            }
            alert(s)
          }
          else{
            console.log(result)
            alert(result.data.data)
          }
          this.$router.push({name:'BeforeSales'})
        }
      }
    }
</script>

<style lang="scss" scoped>
  input::-webkit-outer-spin-button,
  input::-webkit-inner-spin-button {
    -webkit-appearance: none;
  }
  input[type="number"]{
    -moz-appearance: textfield;
  }
  .main {
    width: 100%;
    height: calc(100% - 1px);
    background: #FFFFFF;
    border-top: 1px solid transparent;
    .content {
      width: 406px;
      left: 128px;
      margin: 0 auto;
      .top {
        width: 100%;
        .box {
          width: 100%;
          height: 25px;
          margin-top: 10px;
          .left {
            height: 25px;
            line-height: 25px;
            width: 106px;
            float: left;
            text-align: left;
            font-size: 14px;
          }
          .text_input {
            border-width: 1px;
            width: 298px;
            height: 23px;
          }
          .notselect {
            cursor: default;
          }
        }
      }
      .bottom {
        width: 100%;
        .button {
          margin: 20px auto;
          width: 284px;
          height: 40px;
          line-height: 40px;
          text-align: center;
          font-size: 13px;
          border-radius: 10px;
          border: 1px solid black;
        }
        .button:hover {
          background: #c1e8ff;
          cursor: pointer;
        }
      }
    }
  }
</style>
